/*
 * Copyright (C), 2014-2016, org.esaydev
 * FileName: HandleAccessToken.java
 * Author:   jian
 * Date:     2016年3月21日 
 */
package org.easydev.wechat.client.handle;

import org.apache.commons.lang3.StringUtils;
import org.easydev.wechat.client.dto.base.AccessToken;
import org.easydev.wechat.client.dto.base.BaseParam;
import org.easydev.wechat.client.util.WechatReqConfig;
import org.easydev.wechat.common.constants.WechatErrorCode;
import org.easydev.wechat.common.exception.WechatException;
import org.easydev.wechat.common.util.HttpUtil;

import com.alibaba.fastjson.JSONObject;

/**
 * <Description> 获取accesstoken处理<br>
 */
@Deprecated
public class HandleAccessToken extends WechatRequestHandle {

    /**
     * {@inheritDoc}
     */
    public JSONObject dohandle(BaseParam parsms, WechatReqConfig config) throws WechatException {
        if (!(parsms instanceof AccessToken)) {
            throw new WechatException(WechatErrorCode.PARAMS_ERROR);
        }
        String wechatRes = HttpUtil.sendGet(config.getUrl().concat(castJsonToQueryString((JSONObject) JSONObject.toJSON(parsms))));
        if (StringUtils.isBlank(wechatRes)) {
            throw new WechatException(WechatErrorCode.WECHAT_RESULT_ERROR);
        }
        return JSONObject.parseObject(wechatRes);
    }
}
